package com.itheima.mp.mytest;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.StringUtils;

import java.util.*;

public class StringUtilDemo {

    @Test
    public void test(){
        String value = "aaa,bbb,ccc,eee,fff";
        String[] stringArray = StringUtils.commaDelimitedListToStringArray(value);
        System.out.println(Arrays.toString(stringArray));
    }


    @Test
    public void testMap(){
        Map<String, List<String>> result = new HashMap<>();

        Map<String,String> orgMap = new HashMap<>();
        orgMap.put("A","a,aa,aaa,aaaa");
        orgMap.put("B","b,bb,bbb,bbbb");
        orgMap.put("C","c,cc,ccc,cccc");
        for (Map.Entry<String, String> entry : orgMap.entrySet()) {
            String key = entry.getKey();
            String[] values = StringUtils.commaDelimitedListToStringArray(entry.getValue());
            for (String factoryImplementationName : values) {
                /*result.computeIfAbsent(key, k -> new ArrayList<>())
                        .add(factoryImplementationName.trim());*/
                result.computeIfAbsent(key, k -> {
                            System.out.println("key : " + k + " 对应的value列表不存在，第一次创建");
                    return new ArrayList<>();
                        })
                        .add(factoryImplementationName.trim());
            }

        }
        System.out.println(result);


    }

    @Test
    public void testloadFactoryNames(){
        List<String> configurations = new ArrayList<>(
                SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, StringUtilDemo.class.getClassLoader()));
        System.out.println(configurations);
    }
}
